<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加收件人信息</title>
    <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css">
    <script type="text/javascript" src="../../layui-v2.6.8/layui/layui.js"></script>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">收件人姓名</label>
        <div class="layui-input-block">
            <input type="text" name="acontact" required  lay-verify="required" placeholder="收件人姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收件人电话</label>
        <div class="layui-input-block">
            <input type="text" name="aphone" required  lay-verify="required" placeholder="收件人电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收件人地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" required  lay-verify="required" placeholder="收件人地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;
        var cid = sessionStorage.getItem("cid");

        form.on('submit(formDemo)',function(data){
            $.ajax({
                url:'http://localhost:8080/addAddress'+'?cid='+cid,
                async: true,
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function(data){
                    if (data.code === 0) {
                        layer.msg("添加成功", {icon: 6});
                        setTimeout(function () {
                                location.reload();//刷新页面
                            },
                            1000
                        );
                        location.href = 'Order.html';
                    } else {
                        layer.msg("添加失败", {icon: 5});
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>